package com.googlecode.objectify.test.dataloader;

import com.googlecode.objectify.Key;

/**
 * Helper class to create Objectify keys, mainly used in Smooks.
 * JavaBean expressions
 * @author Shakil Siraj
 *
 */
public class ObjectifyHelper {

    /**
     * Creates a Long based Objectify key.
     * @param type The entity type
     * @param id key id in String form, passed on from Smooks
     * @return The newly created Objectify key
     * @throws Exception thrown from Class object creation
     */
    @SuppressWarnings({ "rawtypes", "unchecked" })
    public final <T> Key<T> createLongBasedKey(final String type,
	    final String id) throws Exception {
	Class clazz = Class.forName(type);
	return Key.create(clazz, Long.parseLong(id));
    }
    /**
     * Creates a String based Objectify key.
     * @param type The entity type
     * @param id Key id
     * @return The newly created Objectify key
     * @throws Exception thrown from Class object creation
     */
    @SuppressWarnings({ "rawtypes", "unchecked" })
    public final <T> Key<T> createStringBasedKey(final String type,
	    final String id) throws Exception {
	Class clazz = Class.forName(type);
	return Key.create(clazz, id);
    }
}
